package com.ushine.web.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ushine.web.base.mapper.UserGroupMapper;
import com.ushine.web.base.model.system.UserGroupDO;
import com.ushine.web.base.service.IUserGroupService;
import com.ushine.web.component.page.PageRequestQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: yls
 * @Date: 2022/02/16 00:03
 * @Description: 用户组实现
 * @Version 1.0
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserGroupServiceImpl extends ServiceImpl<UserGroupMapper, UserGroupDO>
        implements IUserGroupService {

    @Override
    public Boolean insertUserGroup(UserGroupDO userGroup) {
        return save(userGroup);
    }

    @Override
    public Boolean deleteUserGroup(Long id) {
        return removeById(id);
    }

    @Override
    public Boolean updateUserGroup(UserGroupDO userGroup) {
        return updateById(userGroup);
    }

    @Override
    public UserGroupDO getUserGroupByName(String userGroupName) {
        LambdaQueryWrapper<UserGroupDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserGroupDO::getUserGroupName, userGroupName);
        return getOne(lambdaQueryWrapper);
    }

    @Override
    public Page<UserGroupDO> listUserGroups(PageRequestQuery pageRequestQuery) {
        Page<UserGroupDO> page = new Page<>(pageRequestQuery.getPageNum(), pageRequestQuery.getPageSize());
        LambdaQueryWrapper<UserGroupDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        return page(page, lambdaQueryWrapper);
    }
}
